package com.xtpt.disaster.bean;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
public class ClientCmdExecResult {
    private List<List<String>> cmdGroupList;
    private Map<Integer,String[]> errorCmdList;
    private boolean status;
    private List<List<String>> execCmdResult;
    @JsonIgnore
    private List<Integer> groupCmdSize;

    public ClientCmdExecResult()
    {
    }
    public ClientCmdExecResult(List<List<String>> cmds)
    {
        if(cmds!=null && cmds.size()>0)
        {
            groupCmdSize=new ArrayList<>(cmds.size());
            for (List<String> cmd : cmds) {
                groupCmdSize.add(cmd.size());
            }
        }
    }

    public void addErrorCmd(int indexGroup,int indexCmd,String cmd)
    {
        if(groupCmdSize!=null && indexGroup<groupCmdSize.size() && groupCmdSize.get(indexGroup)>indexCmd)
        {
            if(errorCmdList==null)
            {
                errorCmdList=new HashMap<>();
            }
            if(!errorCmdList.containsKey(indexGroup))
            {
                errorCmdList.put(indexGroup,new String[groupCmdSize.get(indexGroup)]);
            }
            errorCmdList.get(indexGroup)[indexCmd]=cmd;
        }
    }
    public void LogCmdResult(int indexGroup,List<String> result)
    {
        if(groupCmdSize!=null && indexGroup<groupCmdSize.size())
        {
            if(execCmdResult==null)
            {
                execCmdResult=new ArrayList<>(groupCmdSize.size());
                for (int i=0;i<groupCmdSize.size();i++)
                {
                    execCmdResult.add(null);
                }
            }
            execCmdResult.set(indexGroup,result);
        }
    }
}
